package com.app.utils;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;

import java.util.ArrayList;

public class TransformController {
	
	public static interface ChangeKEY{

		public static final String INTENT_KEY = "intent_key";
		public static final String BUNDLE_KEY = "bundle_key";
		public static final String FITNESSMAP = "fitness_map";
		public static final String FIT_MAP_REQUEST = "fit_map_request";//地图

	}
	

	public static interface STATE{
		public static final String STATE_KEY = "intent_key";

	}
	
	public static void transformControllerDefaule(Context packageContext,Class<?> clazz){
		Intent intent = new Intent(packageContext,clazz);
		packageContext.startActivity(intent);
	}
	

	public static <T> void  transformControllerModel(Context packageContext,Class<?> clazz,T model){
		Intent intent = new Intent(packageContext,clazz);
		intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		if(model != null){
			Bundle bundle = new Bundle();
			bundle.putParcelable(ChangeKEY.BUNDLE_KEY, (Parcelable) model);
			intent.putExtra(ChangeKEY.INTENT_KEY, bundle);
		}
		packageContext.startActivity(intent);
	}


	public static <T> void  transformControllerModels(Context packageContext,Class<?> clazz,ArrayList<? extends Parcelable> models){
		Intent intetnt = new Intent(packageContext,clazz);
		if(models != null){
			Bundle bundle = new Bundle();
			bundle.putParcelableArrayList(ChangeKEY.BUNDLE_KEY, models);
			intetnt.putExtra(ChangeKEY.INTENT_KEY, bundle);
		}
		packageContext.startActivity(intetnt);
	}
	

	public static <T> void  transformControllerModelState(Context packageContext,Class<?> clazz,T model,String state){
		Intent intetnt = new Intent(packageContext,clazz);
		if(model != null){
			Bundle bundle = new Bundle();
			bundle.putString(STATE.STATE_KEY, state);
			bundle.putParcelable(ChangeKEY.BUNDLE_KEY, (Parcelable) model);
			intetnt.putExtra(ChangeKEY.INTENT_KEY, bundle);
		}
		packageContext.startActivity(intetnt);
	}


	public static <T> void  transformControllerTypeForResult(Activity activity,Class<?> clazz,int type){
		int requestCode = 1;
		Intent intetnt = new Intent(activity,clazz);
		if(type >0){
			Bundle bundle = new Bundle();
			bundle.putInt(ChangeKEY.BUNDLE_KEY,type);
			intetnt.putExtra(ChangeKEY.INTENT_KEY, bundle);
		}
		activity.startActivityForResult(intetnt, requestCode);
	}

	public static <T> void  transformControllerModelForResult(Activity activity,Class<?> clazz,T model){
		int requestCode = 1;
		Intent intetnt = new Intent(activity,clazz);
		if(model != null){
			Bundle bundle = new Bundle();
			bundle.putParcelable(ChangeKEY.BUNDLE_KEY, (Parcelable) model);
			intetnt.putExtra(ChangeKEY.INTENT_KEY, bundle);
		}
		activity.startActivityForResult(intetnt, requestCode);
	}

	public static <T> void  transformControllerModelSForResult(Activity activity,Class<?> clazz,Bundle bundle){
		int requestCode = 1;
		Intent intetnt = new Intent(activity,clazz);
		intetnt.putExtra(ChangeKEY.INTENT_KEY, bundle);
		activity.startActivityForResult(intetnt, requestCode);
	}

	public static void  transformController(Context packageContext,Class<?> clazz){
		transformControllerModel(packageContext, clazz, null);
	}
	

	public static void  transformControllerIntPut(Context packageContext,Class<?> clazz,Bundle bundle){
		Intent intent = new Intent(packageContext,clazz);
		intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		if(bundle != null){
			intent.putExtra(ChangeKEY.INTENT_KEY, bundle);
		}
		packageContext.startActivity(intent);
	}
	
	
}
